package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type JVMSecurityChaosSpec struct {
	// ContainerSelector specifies the target for injection
	ContainerSelector `json:",inline"`

	// BladeCommonSpec contains basic spec of blade chaos action
	// +optional
	BladeCommonSpec `json:",inline"`

	// Duration represents the duration of the chaos
	// +optional
	Duration *string `json:"duration,omitempty"`

	// Action defines the specific jvm http action.
	Action JVMSecurityAction `json:"action"`

	// +optional
	// the latency duration for action 'latency', unit ms
	LatencyDuration int `json:"latency"`
	// +optional
	Offset int `json:"offset"`

	// +optional
	// the exception which needs to throw for action `exception`
	ThrowException string `json:"exception"`

	Username string `json:"username"`

	// RemoteCluster represents the remote cluster where the chaos will be deployed
	// +optional
	RemoteCluster string `json:"remoteCluster,omitempty"`
}

type JVMSecurityAction string

// latency、exception
const (
	JVMSecurityActionLatency   JVMSecurityAction = "latency"
	JVMSecurityActionException JVMSecurityAction = "exception"
)

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
// +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
// +chaos-mesh:experiment

type JVMSecurityChaos struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   JVMSecurityChaosSpec `json:"spec"`
	Status BladeChaosStatus     `json:"status,omitempty"`
}

var _ InnerObjectWithCustomStatus = (*JVMSecurityChaos)(nil)
var _ InnerObjectWithSelector = (*JVMSecurityChaos)(nil)
var _ InnerObject = (*JVMSecurityChaos)(nil)

func init() {
	SchemeBuilder.Register(&JVMSecurityChaos{}, &JVMSecurityChaosList{})
}

// GetSelectorSpecs is a getter for selectors
func (obj *JVMSecurityChaos) GetSelectorSpecs() map[string]interface{} {
	return map[string]interface{}{
		".": &obj.Spec.ContainerSelector,
	}
}

func (obj *JVMSecurityChaos) GetCustomStatus() interface{} {
	return &obj.Status.BladeChaosCustomStatus
}
